package com.ruoyi.interviews.service.impl;

import com.alibaba.fastjson2.JSONObject;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import org.springframework.http.*;

@Service
public class TencentMeetingService {
    private static final String API_URL = "https://api.meeting.qq.com/v1/meetings";
    private static final String SECRET_ID = "AKIDUsQJDRl3FKEFBF8viNuTI6kDFOVkxz04";
    private static final String SECRET_KEY = "795xfBdLD320vmpuwDUwYBkAjCauMsBv";

    public JSONObject createMeeting(String topic, String startTime, int duration, String hostEmail) {
        RestTemplate restTemplate = new RestTemplate();

        // 构造请求体
        JSONObject requestBody = new JSONObject();
        requestBody.put("topic", topic);
        requestBody.put("start_time", startTime); // ISO8601 格式
        requestBody.put("duration", duration); // 单位：分钟
        requestBody.put("host_email", hostEmail);

        // 构造请求头
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.set("X-TC-SecretId", SECRET_ID);
        headers.set("X-TC-SecretKey", SECRET_KEY);

        HttpEntity<String> request = new HttpEntity<>(requestBody.toJSONString(), headers);

        // 发起 POST 请求
        ResponseEntity<String> response = restTemplate.exchange(API_URL, HttpMethod.POST, request, String.class);
        return JSONObject.parseObject(response.getBody());
    }
}
